import 'package:enterprise_v6_app/app/components/dialog/multiple_bottom_sheet/custom_multiple_bottom_sheet.dart';
import 'package:enterprise_v6_app/app/core/ext/widget_extension.dart';
import 'package:enterprise_v6_app/app/data/common/simple_choice_bean.dart';
import 'package:url_launcher/url_launcher.dart';

/// 拨号方法
class DialingFunction {
  ///底部弹窗-选择
  ///[dataList] 数据
  ///[title] 标题
  static selectDialingBottomSheet({
    required List<String> dataList,
    String? title,
  }) async {
    // 不为空
    if (dataList.isEmpty) {
      return;
    }
    // 只有一个号码直接拨号
    if (dataList.length == 1) {
      launchUrl(Uri.parse('tel:${dataList[0]}'));
      return;
    }
    final List<SimpleChoiceBean> beanList = [];
    for (var item in dataList) {
      beanList.add(SimpleChoiceBean(name: item));
    }
    CustomEquipmentBottomSheet<SimpleChoiceBean>(
      dataList: beanList,
      onConfirm: (value) {
        launchUrl(Uri.parse('tel:${value[0].getShowName()}'));
      },
      title: title ?? '电话选择',
      isMultiple: false,
      confirmText: '拨打',
    ).showBottomSheetDialog();
  }
}
